package com.java110.mall.goods.cmd.product;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
import com.java110.core.context.Environment;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.intf.goods.IProductLabelInnerServiceSMO;
import com.java110.po.product.ProductLabelPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;

@Java110Cmd(serviceCode = "product.deleteProductLabel")
public class DeleteProductLabelCmd extends Cmd {
    @Autowired
    private IProductLabelInnerServiceSMO productLabelInnerServiceSMOImpl;

    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        Environment.isDevEnv();
        Assert.hasKeyAndValue(reqJson, "labelId", "labelId不能为空");

    }

    @Override
    @Java110Transactional
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        ProductLabelPo productLabelPo = BeanConvertUtil.covertBean(reqJson, ProductLabelPo.class);
        int flag = productLabelInnerServiceSMOImpl.deleteProductLabel(productLabelPo);

        if (flag < 1) {
            throw new CmdException("删除失败");
        }

    }
}
